package com.aishua.andpaydemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.aishua.andpaydemo.ImageloaderHelper;
import com.aishua.andpaydemo.R;
import com.aishua.andpaydemo.adapter.HomeHotAdapter;
import com.aishua.andpaydemo.adapter.XingquAdapter;

/**
 * Created by aishua on 2018/5/15.
 */

public class DiscoverFragment extends BaseFragment {

    private TextView tv_title;
    private TextView tv_setting;
    private ImageView img_title_xiaoxi;
    private ImageView img_remnetuijian;
    private ImageView img_wodefaixan;
    private RecyclerView rl_xingqu;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = View.inflate(getContext(), R.layout.fragment_discover,null);
        initTitleView( view);
        initView(view);
        initViewData();
        return view;

    }


    private void initTitleView(View view) {

        tv_title = view.findViewById(R.id.tv_title);
        tv_setting = view.findViewById(R.id.tv_setting);
        img_title_xiaoxi = view.findViewById(R.id.img_title_xiaoxi);
        rl_xingqu = view.findViewById(R.id.rl_xingqu);
    }

    private void initView(View view) {

        img_remnetuijian = view.findViewById(R.id.img_remnetuijian);
        img_wodefaixan = view.findViewById(R.id.img_wodefaixan);
        ImageloaderHelper.dispalyImage(getContext(),R.drawable.remnetuijian,img_remnetuijian);
        ImageloaderHelper.dispalyImage(getContext(),R.drawable.wodefaixan,img_wodefaixan);

    }

    private void initViewData() {
        tv_setting.setVisibility(View.INVISIBLE);
        tv_title.setText("发现");
        img_title_xiaoxi.setVisibility(View.GONE);
        String[] xingqu ={"金融","手机","购物","居家","明星","阅读","旅游","视频"};
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 4);
        rl_xingqu.setLayoutManager(layoutManager);
        rl_xingqu.setItemAnimator(new DefaultItemAnimator());
        XingquAdapter xingquAdapter = new XingquAdapter(getContext(), xingqu);
        rl_xingqu.setAdapter(xingquAdapter);
        rl_xingqu.setNestedScrollingEnabled(false);
        xingquAdapter.setonRecycleViewClickListener(new HomeHotAdapter.onRecycleViewClickListener() {
            @Override
            public void onRecycleViewClick(int position) {

                Toast.makeText(getContext(), "positon:" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }



}
